﻿@model ReturnRequestListModel
@inject AdminAreaSettings adminAreaSettings

@{
    var defaultGridPageSize = adminAreaSettings.DefaultGridPageSize;
    var gridPageSizes = adminAreaSettings.GridPageSizes;

    //page title
    ViewBag.Title = T("Admin.ReturnRequests").Text;
    //active menu item (system name)
    Html.SetActiveMenuItemSystemName("Return requests");
}

<nop-antiforgery-token />
<div class="content-header clearfix">
    <h1 class="pull-left">
        @T("Admin.ReturnRequests")
    </h1>
    <div class="pull-right">
        &nbsp;
        @await Component.InvokeAsync("AdminWidget", new { widgetZone = "admin_return_request_list_buttons" })
    </div>
</div>
<div class="content">
    <div class="form-horizontal">
        <div class="panel-group">
            <div class="panel panel-default panel-search">
                <div class="panel-body">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <div class="col-md-4">
                                    <nop-label asp-for="CustomNumber" />
                                </div>
                                <div class="col-md-8">
                                    <nop-editor asp-for="CustomNumber" />
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-md-4">
                                    <nop-label asp-for="StartDate" />
                                </div>
                                <div class="col-md-8">
                                    <nop-editor asp-for="StartDate" />
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-md-4">
                                    <nop-label asp-for="EndDate" />
                                </div>
                                <div class="col-md-8">
                                    <nop-editor asp-for="EndDate" />
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-md-4">
                                    <nop-label asp-for="ReturnRequestStatusId" />
                                </div>
                                <div class="col-md-8">
                                    <nop-select asp-for="ReturnRequestStatusId" asp-items="Model.ReturnRequestStatusList" />
                                </div>
                            </div>

                            <div class="col-md-8 col-md-offset-4">
                                <button type="button" id="search-returnrequests" class="btn btn-primary btn-search">
                                    <i class="fa fa-search"></i>
                                    @T("Admin.Common.Search")
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="panel panel-default">
                <div class="panel-body">
                    <p>
                        @T("Admin.ReturnRequests.Description")
                    </p>
                    <div id="returnrequests-grid"></div>

                    <script type="text/javascript">
                        $(document)
                            .ready(function() {
                                $("#returnrequests-grid")
                                    .kendoGrid({
                                        dataSource: {
                                            type: "json",
                                            transport: {
                                                read: {
                                                    url: "@Html.Raw(Url.Action("List", "ReturnRequest"))",
                                                    type: "POST",
                                                    dataType: "json",
                                                    data: additionalData
                                                }
                                            },
                                            schema: {
                                                data: "Data",
                                                total: "Total",
                                                errors: "Errors"
                                            },
                                            error: function(e) {
                                                display_kendoui_grid_error(e);
                                                // Cancel the changes
                                                this.cancelChanges();
                                            },
                                            pageSize: @(defaultGridPageSize),
                                            serverPaging: true,
                                            serverFiltering: true,
                                            serverSorting: true
                                        },
                                        pageable: {
                                            refresh: true,
                                            pageSizes: [@(gridPageSizes)],
                                            @await Html.PartialAsync("_GridPagerMessages")
                                        },
                                        editable: {
                                            confirmation: "@T("Admin.Common.DeleteConfirmation")",
                                            mode: "inline"
                                        },
                                        scrollable: false,
                                        columns: [
                                            {
                                                field: "CustomNumber",
                                                title: "@T("Admin.ReturnRequests.Fields.CustomNumber")",
                                                width: 100
                                            }, {
                                                field: "ProductName",
                                                title: "@T("Admin.ReturnRequests.Fields.Product")",
                                                width: 350,
                                                template:
                                                    '# if(ProductId > 0) {# <a href="@Url.Content("~/Admin/Product/Edit/")#=ProductId#">#:ProductName#</a> ' +
                                                        '# if(AttributeInfo && AttributeInfo.length > 0) {# <div>#=AttributeInfo#</div> #} # #} else {# order item is deleted #} #'
                                            }, {
                                                field: "Quantity",
                                                title: "@T("Admin.ReturnRequests.Fields.Quantity")",
                                                width: 100
                                            }, {
                                                field: "CustomerId",
                                                title: "@T("Admin.ReturnRequests.Fields.Customer")",
                                                width: 200,
                                                template:
                                                    '<a href="@Url.Content("~/Admin/Customer/Edit/")#=CustomerId#">#:CustomerInfo#</a>'
                                            }, {
                                                field: "CustomOrderNumber",
                                                title: "@T("Admin.ReturnRequests.Fields.CustomOrderNumber")",
                                                width: 200,
                                                headerAttributes: { style: "text-align:center" },
                                                attributes: { style: "text-align:center" },
                                                template: '# if(OrderId > 0) {# <a class="btn btn-default" href="@Url.Content("~/Admin/Order/Edit/")#=OrderId#"><i class="fa fa-eye"></i>#=CustomOrderNumber# - @T("Admin.Common.View")</a> #} else {# order item is deleted #} #'
                                            }, {
                                                field: "ReturnRequestStatusStr",
                                                title: "@T("Admin.ReturnRequests.Fields.Status")",
                                                width: 100
                                            }, {
                                                field: "CreatedOn",
                                                title: "@T("Admin.ReturnRequests.Fields.CreatedOn")",
                                                width: 100,
                                                type: "date",
                                                format: "{0:G}"
                                            }, {
                                                field: "Id",
                                                title: "@T("Admin.Common.Edit")",
                                                width: 100,
                                                headerAttributes: { style: "text-align:center" },
                                                attributes: { style: "text-align:center" },
                                                template: '<a class="btn btn-default" href="Edit/#=Id#"><i class="fa fa-pencil"></i>@T("Admin.Common.Edit")</a>'
                                            }
                                        ]
                                    });
                            });
                    </script>

                    <script type="text/javascript">
                        $(document)
                        .ready(function() {
                            $('#search-returnrequests')
                                .click(function() {
                                    var grid = $('#returnrequests-grid').data('kendoGrid');
                                    grid.dataSource.page(1); //new search. Set page size to 1
                                    //grid.dataSource.read(); we already loaded the grid above using "page" function
                                    return false;
                                });
                        });

                        function additionalData() {
                            var data = {
                                StartDate: $('#@Html.IdFor(model => model.StartDate)').val(),
                                EndDate: $('#@Html.IdFor(model => model.EndDate)').val(),
                                CustomNumber: $('#@Html.IdFor(model => model.CustomNumber)').val(),
                                ReturnRequestStatusId: $('#@Html.IdFor(model => model.ReturnRequestStatusId)')
                                    .val()
                            };
                            addAntiForgeryToken(data);
                            return data;
                        }
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>